import KoaRouter from "@koa/router";
import { RouterConfigType } from "../types/router";
const koaRouter = new KoaRouter();
import routerConfig from "./router-config";

// router.get router.post
routerConfig.map((item : RouterConfigType) => {
  // item : {url , method , callback}
  // 取出请求方式
  const cb =
    item.method.toLowerCase() === "get" ? koaRouter.get : koaRouter.post;
  const path = item.url;
  // router.get('/home',(ctx)=>{//xxxx})
  // cb.call(message)
  cb.call(koaRouter, path, item.callback);
});

export default koaRouter;
